{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 证券资讯\n",
    "\n",
    "- 作者：DGC'Idea\n",
    "- 版本：V0.1  \n",
    "- 更新日期：2018年3月18日"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "auth success \n"
    },
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'jqdata'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-2-91297bd00e46>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'../AT'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mat_news\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mf:\\code\\Python\\Quant\\Quant\\AT\\at_news.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[1;31m# 聚源数据库\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mjqdata\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mjy\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m \u001b[1;31m#研究、策略中区别配置\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'jqdata'"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.append('../AT')\n",
    "from at_news import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_market_news('morning')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.简讯"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "#聚源简讯\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from jqdata import jy\n",
    "\n",
    "today=pd.datetime.today().strftime('%Y-%m-%d')\n",
    "q=query(\n",
    "    #具体时间\n",
    "    jy.ED_GilBroadcast.InfoPublTime,\n",
    "    #标题\n",
    "    jy.ED_GilBroadcast.InfoTitle,\n",
    "    #正文\n",
    "    jy.ED_GilBroadcast.Content,\n",
    ").filter(\n",
    "    #按照发布日期过虑\n",
    "    jy.ED_GilBroadcast.InfoPublDate==today \n",
    ").order_by(\n",
    "    #按照发布时间排序\n",
    "    jy.ED_GilBroadcast.InfoPublTime.desc()\n",
    "    )\n",
    "df=jy.run_query(q)  \n",
    "\n",
    "if len(df)==0:\n",
    "    print ('今天无内容！')\n",
    "else:\n",
    "    for i in range(len(df)):\n",
    "        print (df.iloc[i].InfoTitle )\n",
    "        print (df.iloc[i].InfoPublTime )\n",
    "        print ('-'*len(df.iloc[i].InfoTitle)*2)\n",
    "        print ((df.iloc[i].Content).decode('gbk'),'\\n\\n' )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.文章"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入库\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from jqdata import jy\n",
    "\n",
    "today=pd.datetime.today().strftime('%Y-%m-%d')\n",
    "#获取聚源当天文章\n",
    "q=query(\n",
    "    jy.LC_MarketNews.InfoPublDate,\n",
    "    jy.LC_MarketNews.Author,\n",
    "    jy.LC_MarketNews.XGRQ,\n",
    "    jy.LC_MarketNews.InfoTitle,\n",
    "    jy.LC_MarketNews.Content,\n",
    ").filter(\n",
    "    jy.LC_MarketNews.InfoPublDate==today   \n",
    ").order_by(\n",
    "    #按照发布时间排序\n",
    "    jy.LC_MarketNews.XGRQ.desc()\n",
    ")\n",
    "df=jy.run_query(q)  \n",
    "\n",
    "if len(df)==0:\n",
    "    print ('无内容！')\n",
    "else:\n",
    "    #打印文章\n",
    "    for i in range(len(df)):   \n",
    "        print ('标题：',df.iloc[i].InfoTitle )\n",
    "        print ('时间：',df.iloc[i].XGRQ )\n",
    "        print ('作者：',df.iloc[i].Author )\n",
    "        print ('-'*len(df.iloc[i].InfoTitle)*4)\n",
    "        print (df.iloc[i].Content.replace('\\n',''),'\\n\\n')      #.replace('\\n','').replace('　　','\\n　　')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "from datetime import timedelta,date\n",
    "\n",
    "#供新闻类型、链接和标题\n",
    "df=ts.get_latest_news(top=200000) \n",
    "\n",
    "if len(df)==0:\n",
    "    print (df,'今天无内容！')\n",
    "else:\n",
    "    for i in range(len(df)):\n",
    "        if df.iloc[i].time[0:5]==pd.datetime.today().strftime('%m-%d'):\n",
    "            print (df.iloc[i].time)\n",
    "            print (df.iloc[i].title)\n",
    "            print (df.iloc[i].url,'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.4 64-bit ('base': conda)",
   "language": "python",
   "name": "python37464bitbasecondad5f255661c6c454290a08f256a06a34d"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}